package com.catfive.jet_work.feature.filemanager

import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.requiredSize
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.CenterAlignedTopAppBar
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ListItem
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.catfive.jet_work.R
import com.catfive.jet_work.core.design.component.TopBarIconMenuButton


@Composable
fun FileManagerRoute(onOpenDrawer: () -> Unit) {
    FileManagerScreen(onOpenDrawer = onOpenDrawer)
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun FileManagerScreen(onOpenDrawer: () -> Unit) {
    Scaffold(topBar = {
        CenterAlignedTopAppBar(
            colors = TopAppBarDefaults.topAppBarColors(
                containerColor = MaterialTheme.colorScheme.surfaceVariant.copy(0.6f)
            ),
            navigationIcon = {
                TopBarIconMenuButton(onClick = { onOpenDrawer() })
            },
            title = {
                Text("文件管理", fontSize = 24.sp)
            }
        )
    }
    ) { paddingValue ->
        Surface(modifier = Modifier.padding(paddingValue)) {
            LazyColumn(
                modifier = Modifier
                    .fillMaxWidth() ,
            ) {
                items(20) {
                    ListItem(
                        modifier = Modifier.clickable { },
                        headlineContent = {
                            Text(
                                "123123123",
                                style = MaterialTheme.typography.titleMedium,
                            )
                        },
                        leadingContent = {
                            Card(
                                modifier = Modifier.size(48.dp),
                                shape = RoundedCornerShape(8.dp),
                            ) {
                                Box(modifier = Modifier.fillMaxSize()) {
                                    Image(
                                        modifier = Modifier.align(Alignment.Center),
                                        painter = painterResource(R.drawable.ic_folder_light),
                                        contentDescription = ""
                                    )
                                }
                            }
                        },
                        supportingContent = {
                            Text(
                                modifier = Modifier.padding(top = 4.dp),
                                text = "2025-10-10 00:00:00",
                                style = MaterialTheme.typography.labelSmall,
                                fontWeight = FontWeight.Normal,
                            )
                        }
                    )

                }
            }
        }
    }
}

@Preview
@Composable
fun PreviewFileManager() {
    FileManagerScreen({})
}